package com.qianfeng.day35_slidingmenuuse;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Toast;

import com.jeremyfeinstein.slidingmenu.lib.SlidingMenu;
import com.jeremyfeinstein.slidingmenu.lib.SlidingMenu.OnClosedListener;
import com.jeremyfeinstein.slidingmenu.lib.SlidingMenu.OnOpenedListener;

public class MainActivity extends Activity {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);

		SlidingMenu menu = new SlidingMenu(this);
		// 关联要显示的抽屉里的布局
		menu.setMenu(R.layout.first_layout);
		// 关联第二个布局
		menu.setSecondaryMenu(R.layout.second_layout);
		// 设置抽屉打开的模式
		menu.setMode(SlidingMenu.LEFT_RIGHT);
		// 将抽屉关联到Activity中
		menu.attachToActivity(this, SlidingMenu.SLIDING_CONTENT);
		// 设置抽屉的宽度
		menu.setBehindWidth(300);
		// 触摸屏幕的边缘,打开抽屉
		menu.setTouchModeAbove(SlidingMenu.TOUCHMODE_MARGIN);

		// 第一个抽屉视图
		View firstView = menu.getMenu();
		// 第二个抽屉视图
		// View secondaryVew = menu.getSecondaryMenu();
		Button btnSet = (Button) firstView.findViewById(R.id.btn_setting);
		btnSet.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				Toast.makeText(MainActivity.this, "抽屉设置", Toast.LENGTH_SHORT)
						.show();
			}
		});

		// 打开抽屉时的监听
		menu.setOnOpenedListener(new OnOpenedListener() {

			@Override
			public void onOpened() {
				Toast.makeText(MainActivity.this, "打开抽屉", Toast.LENGTH_SHORT)
						.show();
			}
		});

		// 关闭抽屉的监听
		menu.setOnClosedListener(new OnClosedListener() {

			@Override
			public void onClosed() {
				Toast.makeText(MainActivity.this, "关闭抽屉", Toast.LENGTH_SHORT)
						.show();
			}
		});
		
		//开关抽屉
		//menu.toggle();
	}

}
